package com.bookmanagement.mapper;

import com.bookmanagement.entity.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper {

    @Insert("insert into comment(book_id, user_id, content) values(#{bookId}, #{userId}, #{content})")
    void addComment(Comment comment);

    @Select("select * from comment where book_id = #{bookId} order by create_at desc")
    List<Comment> getCommentsByBookId(Long bookId);

    @Delete("delete from comment where id = #{commentId} and user_id = #{userId}")
    void deleteComment(Long commentId, Long userId);

    @Select("select * from comment where id = #{commentId}")
    Comment getCommentById(Long commentId);

    // 管理端：删除任意评论（不验证用户）
    @Delete("delete from comment where id = #{commentId}")
    void deleteCommentByAdmin(Long commentId);

    // 管理端：获取所有评论
    @Select("select * from comment order by create_at desc")
    List<Comment> getAllComments();

}
